/**
 */
package wcomm_v1.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import wcomm_v1.EndPoint;
import wcomm_v1.InMessage;
import wcomm_v1.OutMessage;
import wcomm_v1.PortDefinition;
import wcomm_v1.Wcomm_v1Package;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Port Definition</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link wcomm_v1.impl.PortDefinitionImpl#getRole <em>Role</em>}</li>
 *   <li>{@link wcomm_v1.impl.PortDefinitionImpl#getOutMsgs <em>Out Msgs</em>}</li>
 *   <li>{@link wcomm_v1.impl.PortDefinitionImpl#getInMsgs <em>In Msgs</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PortDefinitionImpl extends NamedElementImpl implements PortDefinition
{
  /**
   * The cached value of the '{@link #getRole() <em>Role</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRole()
   * @generated
   * @ordered
   */
  protected EndPoint role;

  /**
   * The cached value of the '{@link #getOutMsgs() <em>Out Msgs</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOutMsgs()
   * @generated
   * @ordered
   */
  protected EList<OutMessage> outMsgs;

  /**
   * The cached value of the '{@link #getInMsgs() <em>In Msgs</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getInMsgs()
   * @generated
   * @ordered
   */
  protected EList<InMessage> inMsgs;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected PortDefinitionImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return Wcomm_v1Package.Literals.PORT_DEFINITION;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EndPoint getRole()
  {
    if (role != null && role.eIsProxy())
    {
      InternalEObject oldRole = (InternalEObject)role;
      role = (EndPoint)eResolveProxy(oldRole);
      if (role != oldRole)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, Wcomm_v1Package.PORT_DEFINITION__ROLE, oldRole, role));
      }
    }
    return role;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EndPoint basicGetRole()
  {
    return role;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRole(EndPoint newRole)
  {
    EndPoint oldRole = role;
    role = newRole;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, Wcomm_v1Package.PORT_DEFINITION__ROLE, oldRole, role));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<OutMessage> getOutMsgs()
  {
    if (outMsgs == null)
    {
      outMsgs = new EObjectContainmentEList<OutMessage>(OutMessage.class, this, Wcomm_v1Package.PORT_DEFINITION__OUT_MSGS);
    }
    return outMsgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<InMessage> getInMsgs()
  {
    if (inMsgs == null)
    {
      inMsgs = new EObjectContainmentEList<InMessage>(InMessage.class, this, Wcomm_v1Package.PORT_DEFINITION__IN_MSGS);
    }
    return inMsgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.PORT_DEFINITION__OUT_MSGS:
        return ((InternalEList<?>)getOutMsgs()).basicRemove(otherEnd, msgs);
      case Wcomm_v1Package.PORT_DEFINITION__IN_MSGS:
        return ((InternalEList<?>)getInMsgs()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.PORT_DEFINITION__ROLE:
        if (resolve) return getRole();
        return basicGetRole();
      case Wcomm_v1Package.PORT_DEFINITION__OUT_MSGS:
        return getOutMsgs();
      case Wcomm_v1Package.PORT_DEFINITION__IN_MSGS:
        return getInMsgs();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.PORT_DEFINITION__ROLE:
        setRole((EndPoint)newValue);
        return;
      case Wcomm_v1Package.PORT_DEFINITION__OUT_MSGS:
        getOutMsgs().clear();
        getOutMsgs().addAll((Collection<? extends OutMessage>)newValue);
        return;
      case Wcomm_v1Package.PORT_DEFINITION__IN_MSGS:
        getInMsgs().clear();
        getInMsgs().addAll((Collection<? extends InMessage>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.PORT_DEFINITION__ROLE:
        setRole((EndPoint)null);
        return;
      case Wcomm_v1Package.PORT_DEFINITION__OUT_MSGS:
        getOutMsgs().clear();
        return;
      case Wcomm_v1Package.PORT_DEFINITION__IN_MSGS:
        getInMsgs().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.PORT_DEFINITION__ROLE:
        return role != null;
      case Wcomm_v1Package.PORT_DEFINITION__OUT_MSGS:
        return outMsgs != null && !outMsgs.isEmpty();
      case Wcomm_v1Package.PORT_DEFINITION__IN_MSGS:
        return inMsgs != null && !inMsgs.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //PortDefinitionImpl
